// pages/mine/records/index.js
import { request } from '../../../api/request.js'


Page({

  /**
   * 页面的初始数据
   */
  data: {
    weekSettlementList: [],
    todayOrderList: [],
    // 时间
    currentDate: '',
    currentDateDay: '',
    minDate: new Date().getTime(),
    popupShow: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  todayOrder(e) {
    wx.showLoading({
      title: '加载中',
      success: (res => {
        if (res.errMsg == "showLoading:ok") {
          wx.navigateTo({
            url: "../today/index?date=" + e.currentTarget.dataset.index.dateTime,
            success: (res => {
              if (res.errMsg === "navigateTo:ok") {
                wx.hideLoading()
              }
            })
          })
        }
      })
    })
  },
  // 弹出时间框
  valueIpt() {
    this.setData({ popupShow: true });
  },
  // 时间确定框
  onConfirm(e) {
    var date = this.formatDate(e.detail)
    this.setData({
      currentDate: date.slice(0, 7),
      currentDateDay: date.slice(0, 10),
    });
    this.setData({ popupShow: false });
    request({
      url: "/bill/weekSettlement",
      data: {
        ctime: this.data.currentDate
      }
    }).then(res => {
      if (res.code !== 0) {
        Toast.fail('获取失败');
      }
      var weekSettlementVoList = res.data.weekSettlementVoList
      wx.showLoading({
        title: '加载中',
        success: (res => {
          console.log(res.errMsg)
          if (res.errMsg == "showLoading:ok") {
            wx.hideLoading()
            this.setData({
              weekSettlementList: weekSettlementVoList
            })

          }
        })
      })
    })
  },
  formatDate: function (value) {// 时间戳转换日期格式方法
    if (value == null) {
      return '';
    } else {
      let date = new Date(value);
      let y = date.getFullYear();// 年
      let MM = date.getMonth() + 1;// 月
      MM = MM < 10 ? ('0' + MM) : MM;
      let d = date.getDate();// 日
      d = d < 10 ? ('0' + d) : d;
      let h = date.getHours();// 时
      h = h < 10 ? ('0' + h) : h;
      let m = date.getMinutes();// 分
      m = m < 10 ? ('0' + m) : m;
      let s = date.getSeconds();// 秒
      s = s < 10 ? ('0' + s) : s;
      return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
    }
  }

})